Skip to content

Generate the StackBlitz project files and remove them from the samples - #1152

Open
igdmdimitrov wants to merge 3 commits into
vnextfrom
dmdimitrov/trim-react-samples
Open

igdmdimitrov wants to merge 3 commits into
vnextfrom
dmdimitrov/trim-react-samples

Conversation

@igdmdimitrov

@igdmdimitrov igdmdimitrov commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1151

Summary

Every sample folder held its own package.json, tsconfig.json, index.html, vite.config.js and README.md, more than 5,000 files across about 1,040 samples. The samples browser doesn't use them. The docs use them only to build the "Edit in StackBlitz" project, and they read them from the generated code-viewer JSON (public/code-viewer/**.json), not from the repo. They come from the igniteui-xplat-examples template, and they drifted: old versions (file-saver 1.x, igniteui-theming 25) and packages the sample never imports.

This PR generates the project files with the code-viewer JSON and removes them from every sample. A sample folder now holds only src/ (the sample and the files it imports). It also keeps its own index.html or vite.config.js when it needs a different one.

The PR has three commits. Review the first and the third:

  1. 98e7c69: the generator, templates, discovery and docs changes (18 files).
  2. f008c38: removes the per-sample files (5,187 deletions, no other changes).
  3. 9da334e: a check that fails when project files come back into a sample folder, and the restored generated-sample docs (7 files).

Changes

Sample discovery

  • A sample is any folder with src/index.tsx, matching samples/**/src/index.tsx, no longer package.json. This covers src/utils/sample-index.ts, src/utils/samples.ts and scripts/lib/samples.js.

scripts/generate-code-viewer.js (rewritten)

  • The files and their order don't change: sample sources, then index.html, tsconfig.json, vite.config.js and package.json.
  • package.json lists only what the sample imports. The generator scans JS/TS imports and CSS/SCSS @import/@use/@forward in src/, and the sample's own vite.config.js. It also adds:
    • Ignite UI peer dependencies, resolved recursively.
    • Optional peers behind subpaths: igniteui-react/extras brings marked, shiki and dompurify; igniteui-react/grid-lite brings igniteui-grid-lite.
    • igniteui-webcomponents for igniteui-react-layouts, which imports it without declaring it. Without it, the dashboard tile and Excel workbook samples failed to build.
    • sass when the sample has a .scss file, and @types/<pkg> when the root has it.
    • Build tools (Vite, Tailwind, Sass) go to devDependencies.
  • Versions: root package.json, then SHARED and TOOLING from scripts/lib/versions.js. @infragistics/ names map to their public names. An unknown package falls back to the installed version and prints a warning.
  • tsconfig.json is derived from tsconfig.samples.json, the same options check:samples uses.
  • index.html and vite.config.js come from scripts/lib/templates.js, unless the sample has its own.
  • Plain .js source files are now included. This fixes grids/data-grid/binding-remote-data, which imports a vendored odatajs-4.0.0.js that was missing from its StackBlitz project.

Kept overrides

  • index.html (4): charts/data-chart/type-scatter-polygon-series, type-scatter-polyline-series, excel/spreadsheet/overview and grids/grid-lite/styling-config-themes.
  • vite.config.js (23): 21 Tailwind samples, plus 2 Sass ones (grid-lite styling-config-themes and styling-custom-theme).

Scripts, CI and docs

  • scripts/lib/versions.js: SHARED updates the root package.json and the StackBlitz projects; TOOLING (TypeScript, React types, Vite and its plugins, Tailwind) is for the StackBlitz projects only. Unused jest, vitest, eslint, tslib and node types are removed.
  • scripts/update-ig.js updates only the root package.json, and the CI version-sync step checks only that file.
  • scripts/add-sample.js creates only src/index.tsx and src/index.css.
  • README.md and AGENTS.md:
    • The standalone-run instructions are gone; samples run through npm run dev.
    • They describe the generated project files and the overrides.
    • They keep the "Generated and hand-maintained samples" section, and state that an export from igniteui-xplat-examples should bring only src/.

Check for project files in sample folders

igniteui-xplat-examples still exports samples to this repo. Its template writes a full project per sample, so an export would bring the removed files back.

  • The check: the new scripts/check-sample-files.js runs first in npm run check:samples, which CI runs. A sample folder may hold only src/, plus an index.html or vite.config.js that differs from the template.
  • What counts as a copy: title, charset and whitespace are ignored, so the xplat template's index.html also counts as a copy of ours.
  • Scope: it checks only files git sees, so a local node_modules or build folder in a sample doesn't fail it.
  • skip-type-check.json is again for generated samples whose fix has to land in igniteui-xplat-examples.

Testing

  • Compared against the code-viewer JSON from vnext (1,036 files each):
    • Sample sources are identical.
    • Only binding-remote-data gained a file: the .js above.
    • package.json shrank to what each sample imports, at the root versions.
  • I built one generated project for each distinct dependency set, 41 in total, with npm install and vite build from the registry. All of them built.
  • I ran Grid Overview, Data Annotations and Grid Lite Theming in StackBlitz (openProject, as the docs do):
    • Grid Overview and Data Annotations render.
    • Grid Lite Theming never renders. It doesn't render with the vnext project either, so the problem predates this PR (see Known issues).
  • npm run check: 0 errors. npm run check:samples: the sample folder check passes, and 1,031 samples type-checked.
  • Simulated export: I copied the xplat React template's project files into a sample. The check failed with 5 problems: package.json, tsconfig.json, .devcontainer/, and index.html and vite.config.js as copies of the template.
  • Export with the xplat change: with Export only the sample sources to the React and Web Components repos igniteui-xplat-examples#1084, export --clean --sources-only into this branch changed only src/ and the check passed.
  • BASE_PATH=/react-demos npm run build: 1,036 pages and 1,036 code-viewer files.
  • npm run test:smoke: 28 passed.
  • The React docs, with samples served locally, load the dashboard tile, grid-lite, Tailwind, spreadsheet, chart and grid samples.

Known issues (not changed here)

  • Older samples use the global JSX namespace, so the StackBlitz editor reports Cannot find namespace 'JSX' in them. The samples still run.
  • The 5 samples in skip-type-check.json still need fixes.
  • grids/grid-lite/styling-config-themes never renders in StackBlitz. It didn't before this PR either. Vite starts, but the page stays blank. The sample compiles 8 Sass themes from igniteui-theming, and Sass runs in its slow pure-JS mode there.
  • charts/data-chart/type-scatter-polygon-series and type-scatter-polyline-series load their data from static.infragistics.com/xplatform/json/airplane-*.json, which currently returns 504 or times out. Without the data, only the legend shows.

Follow-ups outside this repo

🤖 Generated with Claude Code

igdmdimitrov and others added 2 commits December 1, 2026 14:05
…lates

Find samples by src/index.tsx instead of package.json, and generate each
sample's StackBlitz project (package.json, tsconfig.json, index.html,
vite.config.js) with the code-viewer JSON:

- package.json lists only the packages the sample imports, at the root
  versions, plus optional peers (igniteui-react/extras, grid-lite) and the
  undeclared igniteui-webcomponents dependency of igniteui-react-layouts
- tsconfig.json comes from tsconfig.samples.json
- index.html and vite.config.js come from templates unless the sample
  keeps its own
- plain .js source files are included (binding-remote-data)

versions.js now drives the root package.json only; TOOLING holds the
StackBlitz toolchain versions. Docs drop the standalone run and the xplat
workflow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Delete package.json, tsconfig.json, README.md, index.html and
vite.config.js from every sample, along with the leftover
sandbox.config.json, .eslintrc.js, .devcontainer and preview images.
Samples that need a different index.html (4) or vite.config.js (21
Tailwind, 2 Sass) keep theirs as overrides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread AGENTS.md Outdated

- **Generated**: change the source in igniteui-xplat-examples (the sample's JSON, or `code-gen-library` for data sources and handlers). Patch the sample here as well only when the fix can't wait for the next export, and say so in the PR. Don't restyle generated code (class components, `IgrXxxModule.register()`, `render(): JSX.Element`); it is the generator's output.
- **Hand-maintained**: function components with hooks, the strict `tsconfig.json` from `npm run add:sample`, and no `register()` calls for `igniteui-react` components, which no longer need them.
All samples are maintained here. About 560, mostly charts, gauges, maps and grids, were exported from igniteui-xplat-examples, which is no longer used. They use class components, `IgrXxxModule.register()` and `render(): JSX.Element`. Leave that style as it is unless you are rewriting the sample; new samples use function components with hooks and no `register()` calls for `igniteui-react` components, which no longer need them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igdmdimitrov @ChronosSF xplat still exports React samples to this repo: its sync-downstream-prs.yml targets vnext and master, and IgniteUI/igniteui-xplat-examples#1068 adds another React template with the same project files.
Steps: run the React sync → export --clean rewrites each sample folder from the template → package.json, tsconfig.json, index.html and vite.config.js are back, and the generator takes the last two as overrides.
Is the React export retired? If not, maybe the sync should write only src/ before this merges, and the "Generated and hand-maintained samples" section should stay?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WC and React PRs updated. Xplat PR here - IgniteUI/igniteui-xplat-examples#1084

igniteui-xplat-examples still exports React samples here, and its
template writes a full project per sample. Add check-sample-files.js to
check:samples, which CI runs: a sample folder may hold only src/, plus
an index.html or vite.config.js that differs from the template.

Restore the generated and hand-maintained samples section in AGENTS.md,
and the generated-sample wording around skip-type-check.json.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread AGENTS.md
A sample runs in the samples browser (`npm run dev`), which needs no per-sample project files. The docs open it in StackBlitz as a standalone Vite project, built from the code-viewer JSON. `npm run generate:code-viewer` creates that project's files:

- `package.json`: the packages the sample imports, plus the Ignite UI packages they need alongside (declared peers, and the optional peers listed in `SUBPATH_PEERS`). Versions come from `scripts/lib/versions.js` and the root `package.json`, so a package a sample imports must be a root dependency.
- `tsconfig.json`: the compiler options of `tsconfig.samples.json`, which `check:samples` uses.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VS Code now shows false errors in every sample file (vnext is fine).
Steps: open samples/inputs/checkbox/overview/src/index.tsx in VS Code → "'React' refers to a UMD global" and "Cannot find module or type declarations for side-effect import of './index.css'".
The root tsconfig.json excludes samples/, so the editor falls back to its defaults. Maybe add samples/tsconfig.json with { "extends": "../tsconfig.samples.json" }?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove the per-sample project files and generate the StackBlitz projects

2 participants